package com.demo.eventbus.service;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 描述：
 * 作者 张超
 * 时间 2018/9/29
 * 项目 springboot-demo v1.0
 * 版本 v1.0
 */
@Configuration
public class EventBusConfig {

    @Bean
    public EventBus getEventBus(){
        LinkedBlockingDeque<Runnable> queue = new LinkedBlockingDeque<>();
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(5, 20, 30, TimeUnit.SECONDS, queue);
        return new AsyncEventBus(poolExecutor);
    }
}
